/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sdd.facades.view;

import com.sdd.entities.Product;
import com.sdd.facades.business.ProductBusinessFacadeBean;
import com.sdd.facades.factories.ProductFactoryFacadeBean;
import com.sdd.plains.CategoryPlain;
import com.sdd.plains.ProductPlain;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author ceu
 */
@Stateless
public class ProductViewFacadeBean implements ProductViewFacade {
    @EJB
    ProductBusinessFacadeBean productBusinessFacadeBean;
    @EJB
    ProductFactoryFacadeBean productFactoryFacadeBean;
    @EJB
    CategoryViewFacade categoryViewFacade;
    
    @Override
    public ProductPlain getProduct(long productId) {
        return productFactoryFacadeBean.createProductPlain(productBusinessFacadeBean.getProduct(productId));
    }

    @Override
    public ProductPlain addProduct(ProductPlain productPlain) {
        return productFactoryFacadeBean.createProductPlain(productBusinessFacadeBean.addProduct(productPlain));
    }

    @Override
    public List<ProductPlain> getAllProducts() {
        return productFactoryFacadeBean.createProductPlain(productBusinessFacadeBean.getAllProducts());
    }
    
    @Override
    public List<ProductPlain> getProducts(int from, int many) {
        return productFactoryFacadeBean.createProductPlain(productBusinessFacadeBean.getProducts(from, many));
    }
    
    @Override
    public List<ProductPlain> getProductsWithoutCategory() {
        return productFactoryFacadeBean.createProductPlain(productBusinessFacadeBean.getProductsWithoutCategory());
    }
    
    
    @Override
    public void addProductToCategoryWithIDs(Long idprod, Long idcat){
        productBusinessFacadeBean.addProductToCategory(idprod, idcat);
    }

    @Override
    public void addProductToCategory(ProductPlain p, List<CategoryPlain> list) {
        productBusinessFacadeBean.addProductToCategory(p, list);
    }

    @Override
    public List<ProductPlain> getStarred() {
        CategoryPlain starred = categoryViewFacade.getCategory("Starred");
        System.out.println("Hasta aqui ok!");
        return productFactoryFacadeBean.createProductPlain(productBusinessFacadeBean.getProductsByCategory(starred));
    }

    @Override
    public List<ProductPlain> getProductsByCategory(Long idcat) {
        CategoryPlain category = categoryViewFacade.getCategory(idcat);
        return productFactoryFacadeBean.createProductPlain(productBusinessFacadeBean.getProductsByCategory(category));
    }

    @Override
    public List<ProductPlain> getProductsWithoutCategory(int from, int many) {
        return productFactoryFacadeBean.createProductPlain(productBusinessFacadeBean.getProductsWithoutCategory(from, many));
    }

    @Override
    public void removeProduct(ProductPlain productPlain) {
        Product product = productBusinessFacadeBean.getProduct(productPlain.getProductId());
        productBusinessFacadeBean.removeProduct(product);
    }
}
